


//
//  CustomeEvaluateSectionView.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/12/12.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "CustomeEvaluateSectionView.h"
#import "ShopEvaluationModel.h"
@interface CustomeEvaluateSectionView()
//@property(nonatomic,strong) UIButton *btn;
@end
@implementation CustomeEvaluateSectionView
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = kWhite;
        
    }
    return self;
}
-(void)setUpUI
{
    CGFloat w =kUIScreen.size.width/4;
    for (int i = 0; i < 4; i++) {
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake((w-64)/2+w*i, (kHeight-22)/2, 64, 22)];
        [self addSubview:btn];
        [btn addTarget: self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = i+1;
        
        NSArray *titles = @[@"全部",@"好评",@"中评",@"差评"];
        btn.layer.masksToBounds = YES;
        btn.layer.cornerRadius = 3;
        
        [btn setTitle:titles[i] forState:UIControlStateNormal];
        long total = self.model.goodsCount + self.model.mediumsCount +self.model.terriblesCount;
        if (i == 0) {
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont systemFontOfSize:14];
           
        }else {
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont systemFontOfSize:11];
            
        }
        if (i == 0) {
            [btn setBackgroundColor:kOrangeBg];
            
        }else if (i == 1||i == 2) {
            [btn setBackgroundColor:[UIColor colorWithRed:242/255.0 green:156/255.0 blue:56/255.0 alpha:0.6]];
            
        }else {
            [btn setBackgroundColor:[UIColor colorWithRed:232/255.0 green:232/255.0 blue:232/255.0 alpha:1]];
        }
        switch (i) {
            case 0:
            {
                 [btn setTitle:[NSString stringWithFormat:@"全部(%ld)",total] forState:UIControlStateNormal];
            }
                break;
            case 1:
            {
                [btn setTitle:[NSString stringWithFormat:@"好评(%ld)",self.model.goodsCount] forState:UIControlStateNormal];
            }
                break;
            case 2:
            {
                [btn setTitle:[NSString stringWithFormat:@"中评(%ld)",self.model.mediumsCount] forState:UIControlStateNormal];
            }
                break;
            case 3:
            {
                [btn setTitle:[NSString stringWithFormat:@"差评(%ld)",self.model.terriblesCount] forState:UIControlStateNormal];
            }
                break;
                
            default:
                break;
        }
    }
    
}
-(void)clickBtn:(UIButton *)clickBtn
{
//    if ([self.delegate respondsToSelector:@selector(evaluationCell:withBtn:)]) {
//        [self.delegate evaluationCell:self withBtn:clickBtn];
//    }
    if ([self.delegate respondsToSelector:@selector(customeEvaluateSectionView:withBtn:)]) {
        [self.delegate customeEvaluateSectionView:self withBtn:clickBtn];
    }
}
- (void)setModel:(ShopEvaluationModel *)model
{
    for (id obj in self.subviews) {
        if ([obj isKindOfClass:[UIButton class]]) {
            XLog(@"obj:%@",obj);
            [obj removeAllObjects];
        }
    }
    _model = model;
    [self setUpUI];
}
@end
